package com.yonyougov.devops.monitor.controller;


import com.yonyougov.devops.fwc.api.dto.BaseResponseDto;
import com.yonyougov.devops.monitor.dto.HardwareInfoRequestDto;
import com.yonyougov.devops.monitor.service.ServerInfoService;
import com.yonyougov.devops.monitor.vo.ServerInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/api/monitor")
@Slf4j
@Valid
public class MonitorController {
    @Autowired
    private ServerInfoService serverInfoService;

    @GetMapping("/test1")
    public Mono<String> test() {
        return Mono.just("aaa");
    }

    @GetMapping("/test2")
    public Flux<String> test2() {
        return Flux.just("dsfsdf");
    }

    @PostMapping("/uploadInfo")
    public Mono<BaseResponseDto> uploadInfo(@RequestBody ServerInfoVo serverInfoVo) {
        log.debug(serverInfoVo.toString());
        serverInfoService.addServerInfo(serverInfoVo);
        return Mono.just(BaseResponseDto.getSuccessInstance());
    }

    @PostMapping("/hardwareInfo")
    public Mono<Map<String, Object>> getHardwareInfo(@RequestBody HardwareInfoRequestDto hardwareInfoRequestDto) {
        return Mono.just(serverInfoService.findHardwareInfo(hardwareInfoRequestDto));
    }
}
